Convert a binary number to decimal numberΒΆ
Convert a binary number to decimal number
Input:
Input a binary number: 101011
Expected output:
The decimal value of the number is: 43
b_num = list(input("Input a binary number: "))
value = 0
for i in range(len(b_num)):
igit = b_num.pop()
if digit == '1':
value = value + pow(2, i)
print("The decimal value of the number is: ", value)
Output:
Input a binary number: 1000001
The decimal value of the number is: 65